package com.sharengo.sms;

import org.apache.commons.codec.binary.Base64;

import java.io.UnsupportedEncodingException;

public class Message {
    /**
     * 自定义流水编号,自动生成
     */
    private String msgId;
    /**
     * 通道号默认是*，不超过20位长度
     */
    private String pszSubPort;
    /**
     * 电话号码
     */
    private String phoneNum;
    /**
     * 短信内容
     */
    private String content;

    public Message( String phoneNum, String content) {
        this.msgId = Sms.generateMsgId();
        this.pszSubPort = "*";
        this.phoneNum = phoneNum;
        this.content = content;
    }

    public Message(String pszSubPort, String phoneNum, String content) {
        this.msgId = Sms.generateMsgId();
        this.pszSubPort = pszSubPort;
        this.phoneNum = phoneNum;
        this.content = content;
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public String getPszSubPort() {
        return pszSubPort;
    }

    public void setPszSubPort(String pszSubPort) {
        this.pszSubPort = pszSubPort;
    }

    public String getPhoneNum() {
        return phoneNum;
    }

    public void setPhoneNum(String phoneNum) {
        this.phoneNum = phoneNum;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder.append(this.msgId);
        try {
            stringBuilder.append("|").append(this.pszSubPort).append("|")
                    .append(this.phoneNum).append("|")
                    .append(Base64.encodeBase64String(this.content.getBytes("GBK")));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return stringBuilder.toString();
    }
}
